#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

int denoValue[255];
int suitValue[255];

class Card{
public:
	int suit;
	int deno;
	Card(char *s) {
		suit = suitValue[s[1]];
		deno = denoValue[s[0]];
	}
	Card(void) {suit=deno=0;}
};

bool operator < (const Card& a, const Card& b) {
	return a.deno < b.deno;
}

ostream& operator << (ostream& out, const Card& c) {
	for (int i=0; i<255; ++i)
		if (denoValue[i] == c.deno) {
			out << char(i);
			break;
		}
	for (int i=0; i<255; ++i)
		if (suitValue[i] == c.suit) {
			out << char(i);
			break;
		}
	return out;
}

int trump;

class Player{
public:
	vector<Card> cards[4];
	int score;

	void receive(Card c) {
		cards[c.suit].push_back(c);
	}

	void arrange(void) {
		for (int i=0; i<4; ++i)
			sort(cards[i].begin(), cards[i].end());
	}

	void clear(void) {
		for (int i=0; i<4; ++i) cards[i].clear();
		score = 0;
	}

	Card play(const Card& c) {
		cards[c.suit].pop_back();
		return c;
	}
	Card play(const int& s) {
		Card c = cards[s].back();
		cards[s].pop_back();
		return c;
	}

	Card findHighest(void) {
		Card biggestEachSuit[4];
		for (int i=0; i<4; ++i)
			if (cards[i].size() > 0)
				biggestEachSuit[i] = cards[i].back();
			else
				biggestEachSuit[i].deno = -1;

		sort(biggestEachSuit, biggestEachSuit+4);
		if (biggestEachSuit[2] < biggestEachSuit[3])
			return biggestEachSuit[3];
		else {
			Card tmp = biggestEachSuit[3];
			for (int i=3; i>0; --i)
				if (biggestEachSuit[i].deno == biggestEachSuit[i-1].deno) {
					if (biggestEachSuit[i].suit == trump && biggestEachSuit[i].deno != -1) {
						return biggestEachSuit[i];
					}
					else if (biggestEachSuit[i-1].suit == trump && biggestEachSuit[i-1].deno != -1) {
						return biggestEachSuit[i-1];
					}
					else if (tmp.suit < biggestEachSuit[i].suit) {
						tmp = biggestEachSuit[i];
						if (i==1 && tmp.suit < biggestEachSuit[i-1].suit)
							tmp = biggestEachSuit[i-1];
					}
				}
				else break;
			return tmp;
		}
	}

	void show(int suit=-1) {
		if (suit == -1) {
			for (int i=0; i<4; ++i) {
				cout << "suit " << i << ": ";
				for (unsigned int j=0; j<cards[i].size(); ++j)
					cout << cards[i][j] << " ";
				cout << endl;
			}
		}
	}
};


Card cards[60];
Player players[10];

int playTrick(int leader) {
	vector<Card> onTable;

	//leader
	onTable.push_back(players[leader].play(players[leader].findHighest()));

	Card first = onTable[0];
	//follower
	for (int i=leader+1; i<leader+5; ++i) {
		int curPlayer = i%5;
		if (players[curPlayer].cards[first.suit].size()>0)
			onTable.push_back(players[curPlayer].play(first.suit));
		else if (players[curPlayer].cards[trump].size()>0)
			onTable.push_back(players[curPlayer].play(trump));
		else onTable.push_back(players[curPlayer].play(players[curPlayer].findHighest()));
	}

	int winner = 0;
	for (int i=1; i<5; ++i) {
		if (onTable[i].suit == trump) {
			if ((onTable[winner].suit != trump) ||
				(onTable[winner].deno < onTable[i].deno))
				winner = i;
		}
		else if (onTable[i].suit == first.suit) {
			if (onTable[winner].suit != trump && onTable[i].deno>onTable[winner].deno)
				winner = i;
		}
	}

	winner = (leader+winner)%5;
	for (int i=0; i<5; ++i)
		if (onTable[i].suit == suitValue['H'])
			players[winner].score+=onTable[i].deno;

	return winner;
}

int main(void)
{
	for (int i=0; i<255; ++i) suitValue[i] = -1;
	for (char ch = '2'; ch <= '9'; ++ch)
		denoValue[ch] = ch - '0';
	denoValue['T'] = 10;
	denoValue['J'] = 11;
	denoValue['Q'] = 12;
	denoValue['K'] = 13;
	denoValue['A'] = 14;
	suitValue['S'] = 3;
	suitValue['H'] = 2;
	suitValue['D'] = 1;
	suitValue['C'] = 0;


	while (true) {
		char str[10];
		scanf(" %s", str);
		if (str[0] == '#') break;
		cards[0] = Card(str);
		for (int i=1; i<52; ++i) {
			scanf(" %s", str);
			cards[i] = Card(str);
		}

// 		reverse(cards, cards+52);

		for (int i=0; i<5; ++i) players[i].clear();

		int idx = 0;
		for (int i=0; i<10; ++i) {
			for (int j=0; j<5; ++j)
				players[j].receive(cards[idx++]);
		}

		for (int i=0; i<5; ++i)
			players[i].arrange();

// 		for (int i=0; i<5; ++i)
// 			players[i].show();

		if (cards[idx]<cards[idx+1]) trump = cards[idx+1].suit;
		else if (cards[idx+1]<cards[idx]) trump = cards[idx].suit;
		else trump = max(cards[idx].suit, cards[idx+1].suit);

		int leader = 0;
		for (int i=0; i<10; ++i)
			leader = playTrick(leader);

		cout << setw(3) << right << players[4].score;
		for (int i=0; i<4; ++i)
			cout << setw(3) << right << players[i].score;
		cout << endl;
	}

	return 0;
}
